<template>
	<!-- 判断是否第一次打开 -->
	<view class="content" v-if="firstLogin == 'yes'">
		<!-- 引导轮播图 -->
		<swiper :indicator-dots="true" :duration="1000" :style="{width : '100vw',height: '100vh'}">
			<swiper-item v-for="x in 4" :key="x">
				<view class="swiper-item">{{x}}</view>
			</swiper-item>
			<swiper-item>
				<view class="swiper-item last">
					<button class="btn" @click="goIndex">开始使用</button>
					<button class="btn" @click="showModel = true">网络设置</button>
				</view>
			</swiper-item>
		</swiper>
		<!-- 模态框 -->
		<view class="model" v-show="showModel">
			<view class="net-Set">
				<label for="host">服务器地址</label>
				<input type="text" v-model="host" id="host">
				<label for="port">服务器端口</label>
				<input type="text" v-model="port" id="port">
				<button @click="setNet">修改</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				firstLogin: uni.getStorageSync("firstLogin") || 'yes',
				swiperRows: [],
				showModel: false,
				// 默认
				host: "http://124.93.196.45",
				port: "10001"
			}
		},
		created() {
			// 设置默认URL地址
			uni.setStorageSync("BASE_URL", this.host + ":" + this.port)
			const that = this
			if (this.firstLogin == "no") {
				uni.switchTab({
					url: "/pages/index/index"
				})
			}
			// 引导页图片接口挂了
			// uni.request({
			// 	url:"http://124.93.196.45:10001/prod-api/api/rotation/list",
			// 	data: {
			// 		type : 1 
			// 	},
			// 	success(res) {
			// 		that.swiperRows = res.data.rows
			// 	}
			// })
		},
		methods: {
			// 修改缓存中的服务器地址
			setNet() {
				uni.setStorageSync("BASE_URL", this.host + ":" + this.port)
				this.showModel = false
				uni.showToast({
					icon: 'success',
					title: "修改成功!"
				})
			},
			// 跳转到主页面
			goIndex() {
				uni.switchTab({
					url: "../index/index",
					success() {
						uni.setStorageSync("firstLogin", 'no')
					}
				})
			}
		}
	}
</script>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: relative;
	}

	.last {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 100%;
	}

	.last>*+* {
		margin-top: 1em;
	}

	.model {
		position: absolute;
		left: 25%;
		right: 25%;
		top: 30%;
		bottom: 30%;
		background-color: azure;
	}

	.net-Set {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 100%;
	}

	.net-Set>*+* {
		margin-top: 1em;
	}

	.net-Set>input {
		width: 80%;
		height: 3em;
		padding-left: 2em;
		background-color: #e7e8e8;
		border-radius: 5px;
	}
</style>
